package game;

import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Point2D;

public class Bomb extends AnimatedSprite
{	

	
	private static final long serialVersionUID = 1L;
	float time;
	boolean detonada = false;
	int DistanceX = 40;
	int enemieAnimationType;
	boolean jacolidi = false;
	float speed = 3;

	public Bomb(Point pos,int enemyAnimationType) 
	{
		super(67, pos, new Point(35,35), new Point(0,0), new Point(35,35), new Point(8,1), 0.02f, false);
		this.enemieAnimationType = enemyAnimationType;
		//Audios.getInstance().Play(9);
	}
	
	public void Update(Player p, Rectangle[] rectMapa) 
	{
		time += Time.getInstance().getLoopTime();
		
		if(enemieAnimationType == 1)
		this.setPosition(new Point2D.Double(this.position.getX(), this.position.getY() + speed));
		
		else if(enemieAnimationType == 2)
		this.setPosition(new Point2D.Double(this.position.getX() -speed, this.position.getY()));
		
		else if(enemieAnimationType == 3)
			this.setPosition(new Point2D.Double(this.position.getX() , this.position.getY() - speed));
		
		else if(enemieAnimationType == 4)
			this.setPosition(new Point2D.Double(this.position.getX() + speed, this.position.getY()));
				
		DistanceX --;
		if(Colisao(p))
		{
			if(jacolidi == false)
			{
				
				Player.addHP(-20);
				jacolidi = true;
				Inimigo_04.bombs.remove(this);
				
				Explosao.IniciarExplosao(getRectangle(), 0.01f);
			}
		}
		
		else if(time >= 1)
		{
			Explodir();
		}
		else
		{
			for(Rectangle rect : rectMapa)
			{
				if(rect.intersects(getRectangle()))
					Explodir();
			}
		}
		
		
		
		super.Update();
	}
	
	@Override
	public void draw(Graphics2D g2d) 
	{
		super.draw(g2d);
	}
	
	public void Explodir()
	{
		Inimigo_04.bombs.remove(this);
		Explosao.IniciarExplosao(getRectangle(), 0.01f);
	}
}